package My.BasicDisciplineTools.Math;

//等差数列类,n属于正整数
public class EqualDifferenProgerssion {
    //前n项和(直接输入第几项)
    public int getTheFirst_n_Terms(int n){
       if(n>=0){
            return (n*(1+n))/2;
        }else {
           return 0;
       }
    }
    //前n项和(首项，公差，项数n)
    public int getTheFirst_n_Terms(int a1,int d,int n){
        if(n>=0){
            return a1*n+(n*(n-1)*d)/2;
        }else {
            return 0;
        }
    }
    //获取第n项的值an
    public int getan(int a1,int d,int n){
        if(n>=0){
            return a1+(n-1)*d;
        }else {
            return 0;
        }
    }
}
